package com.liang.cloud.Config;

import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.service.WxPayService;
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * @author: 余亮亮
 * @description:微信支付相关
 * @create: 2020-01-02 16:30:48
 **/
@Component
public class WeXinPayConfig {
    @Autowired
    private WxPayProperties wxPayProperties;



    @Bean
    public WxPayService wxPayService(){
        WxPayService wxPayService = new WxPayServiceImpl();
        wxPayService.setConfig(wxPayConfig());
        return wxPayService;
    }
    @Bean
    public WxPayConfig wxPayConfig(){
        WxPayConfig payConfig = new WxPayConfig();
        payConfig.setAppId(wxPayProperties.getAppid());
        payConfig.setMchId(wxPayProperties.getMchId());
        payConfig.setMchKey(wxPayProperties.getMchKey());
        payConfig.setKeyPath(wxPayProperties.getKeyPath());
        payConfig.setTradeType(wxPayProperties.getTradeType());
        payConfig.setNotifyUrl(wxPayProperties.getNotifyUrl());

        // 可以指定是否使用沙箱环境
        payConfig.setUseSandboxEnv(true);
        return payConfig;
    }

}
